﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;

namespace TheFinalCountDown
{
	[Serializable]
	public class UserSettings
	{
		public static UserSettings Instance = UserSettings.Default;

		public String FormatFunctionName;
		public DateTime TargetDate;
		public Boolean IsEffectiveTime;

		public static void Save(String filePath)
		{
			FileStream fileStream = new FileStream(filePath, FileMode.Create);
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			binaryFormatter.Serialize(fileStream, Instance);
			fileStream.Close();
		}

		public static void Load(String filePath)
		{
			if (File.Exists(filePath))
			{
				FileStream fileStream = new FileStream(filePath, FileMode.Open);
				BinaryFormatter binaryFormatter = new BinaryFormatter();
				Instance = binaryFormatter.Deserialize(fileStream) as UserSettings;
				fileStream.Close();
			}
			else
			{
				Instance = UserSettings.Default;
			}
		}

		#region Get and Set

		public static UserSettings Default
		{
			get
			{
				UserSettings defaultUserSettings = new UserSettings();
				defaultUserSettings.FormatFunctionName = "FullFormat";
				defaultUserSettings.TargetDate = new DateTime(2012, 12, 31, 23, 59, 59);
				defaultUserSettings.IsEffectiveTime = false;
				return defaultUserSettings;
			}
		}

		#endregion
	}
}
